/*
 * marketsim-eclipsetrader
 *
 * Copyright (C) 2008-2011 Steve Phelps and John Cartlidge
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 */
/*
 *  (C) Victria Ltd. 2007
 */
package victria.marketsim.util;

import java.util.Date;

import cern.jet.random.engine.MersenneTwister;

public class ThreadSafeMersenneTwister extends MersenneTwister {

	protected int seed = -1;
	
	public ThreadSafeMersenneTwister() {
		super();
	}

	public ThreadSafeMersenneTwister(Date d) {
		super(d);
	}

	public ThreadSafeMersenneTwister(int seed) {
		super(seed);	
	}


	@Override
	public synchronized int nextInt() {
		return super.nextInt();
	}


	@Override
	public synchronized void setSeed(int seed) {
		this.seed = seed;
		if (seed > 0) {
			super.setSeed(seed);
		} else {
			Date now = new Date();
			super.setSeed((int)now.getTime());
		}
	}
	
	public int getSeed() {
		return seed;
	}
	
	
	
}
